package org.taobao.ibatiside.ui.adapter;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.model.IWorkbenchAdapter2;
import org.eclipse.ui.model.IWorkbenchAdapter3;
import org.taobao.ibatiside.core.filemodel.IbatisConfigFile;
import org.taobao.ibatiside.core.filemodel.IbatisMapperFile;
import org.taobao.ibatiside.core.filemodel.IbatisProject;
import org.taobao.ibatiside.core.filemodel.IbatisStatement;

public class IbatisElementAdapterFactory implements IAdapterFactory {

	@Override
	public Object getAdapter(Object adaptableObject, Class adapterType) {
		if (IWorkbenchAdapter.class.equals(adapterType) || IWorkbenchAdapter2.class.equals(adapterType) || IWorkbenchAdapter3.class.equals(adapterType)){
			if (adaptableObject instanceof IbatisConfigFile){
				return new ConfigFileAdapter((IbatisConfigFile)adaptableObject);
			}else if (adaptableObject instanceof IbatisMapperFile){
				return new MapFileAdapter((IbatisMapperFile)adaptableObject);
			}else if (adaptableObject instanceof IbatisStatement){
				return new StatementAdapter((IbatisStatement)adaptableObject);
			}else if (adaptableObject instanceof IbatisProject){
				return new ProjectAdapter((IbatisProject)adaptableObject);
			}
		}else if (IFile.class.equals(adapterType) || IResource.class.equals(adapterType)){
			if (adaptableObject instanceof IbatisConfigFile){
				return ((IbatisConfigFile)adaptableObject).getConfigFile();
			}else if (adaptableObject instanceof IbatisMapperFile){
				return ((IbatisMapperFile)adaptableObject).getSqlmapFile();
			}else if (adaptableObject instanceof IbatisProject){
				return ((IbatisProject)adaptableObject).getProject();
			}
		}
		return null;
	}

	@Override
	public Class[] getAdapterList() {
		return new Class[]{IWorkbenchAdapter.class,IResource.class, IFile.class};
	}

}
